package licode.unisop.realm.adapter.web;

import licode.unisop.provider.info.UserIdInfo;
import licode.unisop.provider.vo.SiAccount;
import licode.unisop.provider.vo.SiUser;
import licode.unisop.provider.vo.SiUserBrief;
import licode.unisop.realm.client.api.SiUserQueryService;
import licode.unisop.unilite.result.UniReturnResult;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * 适配RESTFUL接口访问，处理用户信息的查询（这里需要做权限控制）
 * 只有拥有user-admin角色的用户才有权限获取用户信息
 *
 * @author WR
 */
@RestController
@UniReturnResult
@RequestMapping("/user-api/v1/internal/user/query")
public class UserQueryController {

    @Resource
    private SiUserQueryService siUserQueryService;

    @PostMapping("/lookup")
    public SiUser lookupUser(@RequestBody UserIdInfo idInfo) {
        return siUserQueryService.lookupUserById(idInfo);
    }

    @PostMapping("/lookup-account")
    public SiUser lookupUser(@RequestBody SiAccount idInfo) {
        return siUserQueryService.lookupUserByAccount(idInfo);
    }

    @PostMapping("/lookup-brief")
    public SiUserBrief lookupUserBrief(@RequestBody UserIdInfo idInfo) {
        return siUserQueryService.lookupUserBriefById(idInfo);
    }

    @PostMapping("/lookup-brief-account")
    public SiUserBrief lookupUserBrief(@RequestBody SiAccount idInfo) {
        return siUserQueryService.lookupUserBriefByAccount(idInfo);
    }
}
